package itbour.onetouchshow.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import java.util.List;

import itbour.onetouchshow.bean.canvas.CompoundPathsBean;
import itbour.onetouchshow.bean.canvas.PathsBean;
import itbour.onetouchshow.utils.CommonUtils;
import itbour.onetouchshow.utils.UIUtils;

/**
 * Created by zjl_d on 2017/12/7.
 * 用于标记视频当前选中的文字区域
 */

public class BoundView extends View {
    public CompoundPathsBean compoundPath;
    private Paint paint;
    private int vW;
    private int vH;

    public BoundView(Context context) {
        this(context, null);
    }

    public BoundView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BoundView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initPaint();
    }

    private void initPaint() {
        paint = new Paint();
        paint.setColor(Color.parseColor("#1FB8B8")); //设置画笔颜色
        paint.setStrokeWidth(UIUtils.dip2px(2));//设置画笔宽度
        paint.setStyle(Paint.Style.STROKE);
        paint.setAntiAlias(true);
    }


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        List<PathsBean> paths = compoundPath.getPaths();
        float mW = (int) compoundPath.getW();
        float mH = (int) compoundPath.getH();

        Path dataPath = CommonUtils.getBoundViewPaths(paths, vW, vH, mW, mH);


        canvas.drawPath(dataPath, paint);

    }

    public void setData(CompoundPathsBean compoundPath, int vW, int vH) {
        this.compoundPath = compoundPath;
        this.vW = vW;
        this.vH = vH;
    }
}
